<?php
session_start();
include_once "objs/User.php";
include_once "models/UserDao.php";
include_once "models/Util.php";
include_once "models/MySqlDataAccessHelper.php";

$leftContent = 'dangkileft.php';

$msgError = Util::getRequestParam('error');
$user = Util::getSessionParam('user');

$act = Util::getRequestParam('act');
if ($act == 'reg') {
    $name = Util::getRequestParam('jformname');
    $email = Util::getRequestParam('jformemail1');
    $passwd1 = Util::getRequestParam('jformpassword1');
    $passwd2 = Util::getRequestParam('jformpassword2');

    if($passwd1 != $passwd2){
        $msgError = 'Mật khẩu nhập lại ko đúng';
    }
    if($msgError != NULL){
        echo "<script>location.href='dangki.php?error=$msgError'</script>";
    }else{
        $md5Pass = md5($passwd1);
        $user = UserDao::insertUser($name, $email, $md5Pass);
        if($user != NULL){
           // Util::freeSessionParam('user');
            $_SESSION['user'] = $user;
            echo "<script>location.href='index.php'</script>";
        }else{
            $msgError = 'Email đã tồn tại';
            echo "<script>location.href='dangki.php?error=$msgError'</script>";
        }
    }
}

include 'subs/template.php';
?>

